package com.ruoyi.project.his.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.his.system.domain.ExamType;
import com.ruoyi.project.his.system.domain.HisDepartment;
import com.ruoyi.project.his.system.domain.HisExamCost;
import com.ruoyi.project.his.system.domain.HisRegistryCost;
import com.ruoyi.project.his.system.service.HisExamCostService;
import com.ruoyi.project.his.system.service.IHisDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/his/examCost")
public class HisExamCostController extends BaseController {
    //声明业务层属性
    @Autowired
    private HisExamCostService hisExamCostService;

    /**
     * 根据检查费ID获取详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:post:query')")
    @GetMapping("examType")
    public AjaxResult getExamType()
    {
        List<ExamType> examTypes = hisExamCostService.selectExamCostByType();
        System.out.println(examTypes+"---------------------------");
        return AjaxResult.success(hisExamCostService.selectExamCostByType());
    }
    /**
     * 新增科室信息
     * @RequestBody 表明请求数据就是请求体 请求数据就是一个大json、
     *
     */
    //@PreAuthorize("@ss.hasPermi('system:post:add')")
    @Log(title = "检查费管理", businessType = BusinessType.INSERT)
    @PostMapping("/addExamCost")
    public AjaxResult add(@RequestBody HisExamCost hisExamCost) {

        hisExamCost.setCreateBy(SecurityUtils.getUsername());

        return toAjax(hisExamCostService.insertExamCost(hisExamCost));
    }
    /**
     * 获取检查费列表
     */
    // @PreAuthorize("@ss.hasPermi('system:post:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisExamCost hisExamCost)
    {
        startPage();
        List<HisExamCost> hisExamCosts = hisExamCostService.selectHisExamCostList(hisExamCost);
        return getDataTable(hisExamCosts);
    }
    /**
     * 根据检查费ID获取详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:post:query')")
    @GetMapping(value = "/{examCostId}")
    public AjaxResult getInfo(@PathVariable Long examCostId)
    {
        return AjaxResult.success(hisExamCostService.selectExamCostById(examCostId));
    }
    /**
     * 修改科室
     */
    // @PreAuthorize("@ss.hasPermi('system:post:edit')")
    @Log(title = "检查费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit( @RequestBody HisExamCost hisExamCost)
    {
        hisExamCost.setUpdateBy(SecurityUtils.getUsername());//给接请求数据实体类赋默认值，谁改的的是谁
        return toAjax(hisExamCostService.updateExamCost(hisExamCost));
    }
    /**
     * 删除科室
     */
    // @PreAuthorize("@ss.hasPermi('system:post:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examCostIds}")
    public AjaxResult remove(@PathVariable Long[] examCostIds)
    {
        return toAjax(hisExamCostService.deleteExamCostByIds(examCostIds));
    }

}
